package fatworm.concept.datatype;
/**
 * date type TIMESTAMP
 */
public class FatTimestamp extends fatworm.concept.DataType{
	private static final FatTimestamp instance = new FatTimestamp();
	public static FatTimestamp getInstance(){
		return instance;
	}
	
	private FatTimestamp(){}
	public TimestampValue convert(SqlValue value) throws ConvertException {
		switch( value.getType().getTypeKey() ){
			case T_STRING:
				try{
					return new TimestampValue( java.sql.Timestamp.valueOf( value.toString()));
				}catch( java.lang.IllegalArgumentException e){
					throw new ConvertException( value , this );
				}
			case T_TIMESTAMP: return (TimestampValue)value;
			default		: throw new ConvertException( value , this );
		}
	} 
	
	public int getTypeKey() {
		return T_TIMESTAMP;
	}
	
	public String toString() {
		return "TIMESTAMP";
	}	
	
	public class TimestampValue extends SqlValue{
		public java.sql.Timestamp value;
		private TimestampValue( java.sql.Timestamp value ){
			this.value = value;
		}
		public String toString(){
			return  value.toString();
		}
		public int compareTo(TimestampValue o) {
			return value.compareTo( o.value );
		}
	}
}
